﻿function getAgentId() {
	    var ua = navigator.userAgent.toLowerCase();
	    if (ua.match(/MicroMessenger/i) == "micromessenger") {
			if (ua.match("mac") == "mac"){
				return "iphone";
			}
			else{
				return "android";	
			}
	    } else {
	        return "web";
	    }
}

function detectmob() {
    if (navigator.userAgent.match(/Android/i)
    || navigator.userAgent.match(/webOS/i)
    || navigator.userAgent.match(/iPhone/i)
    || navigator.userAgent.match(/iPad/i)
    || navigator.userAgent.match(/iPod/i)
    || navigator.userAgent.match(/BlackBerry/i)
    || navigator.userAgent.match(/Windows Phone/i)
    ) {
        return true;
    }
    else {
        return false;
    }
}

function IsWXNativePay() {
    var isWXNativePay = $.cookie('isWXNativePay');
    if (isWXNativePay == '1') {
        return true;
    }
    else {
        return false;
    }
}

function IsWeiXinPay(weixinpay, alipaydiv) {

    var agentId = getAgentId();
    var wxNumber = getwxnumber();
    var isOnPhone = detectmob();

    /*console.log("wxNumber = " + wxNumber);*/
    //if (wxNumber != '' && agentId != "web") {
    if (isOnPhone) {
        $("#" + weixinpay).show();
        //$("#flowlink").show();
        /*微信选中状态*/
        $("#" + alipaydiv).removeClass("active")
            .find(".radiospan").removeClass("radiospanchecked radiospannochecked").addClass("radiospannochecked");
        $("#" + weixinpay).addClass("active")
            .find(".radiospan").removeClass("radiospannochecked").addClass("radiospanchecked");
        $("#" + weixinpay).find(":radio").prop("checked", true);
        
    } else {
        $("#" + weixinpay).hide();
        //$("#flowlink").hide();

        /*支付宝选中状态*/
        $("#" + weixinpay).removeClass("active")
            .find(".radiospan").removeClass("radiospanchecked radiospannochecked").addClass("radiospannochecked");
        $("#" + alipaydiv).addClass("active")
            .find(".radiospan").removeClass("radiospannochecked").addClass("radiospanchecked");
        $("#" + alipaydiv).find(":radio").prop("checked", true);
    }

    //微信二维码支付
    if (IsWXNativePay()) {
        $("#" + weixinpay).show();//显示微信支付按钮
        $("#" + alipaydiv).hide();//隐藏支付宝按钮
        /*微信选中状态*/
        $("#" + alipaydiv).removeClass("active")
            .find(".radiospan").removeClass("radiospanchecked radiospannochecked").addClass("radiospannochecked");
        $("#" + weixinpay).addClass("active")
            .find(".radiospan").removeClass("radiospannochecked").addClass("radiospanchecked");
        $("#" + weixinpay).find(":radio").prop("checked", true);
    }
}




		
			
function mask() {
    var agentId = getAgentId();
   
    if (agentId != "web") {
        var imageName = 'live_weixin_iphone.png';
        if (agentId == "android") {
            imageName = 'live_weixin_android.png';
        }
        else if (agentId == "iphone") {
            imageName = 'live_weixin_iphone.png';
        }
        var weixinTip = $('<div id="weixinTip"><p><img class="payMemo" src="images/' + imageName + '" alt="微信打开"/></p></div>');
        $("body").append(weixinTip);

        var winHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight;
        $("#weixinTip").css({
            "position": "fixed",
            "left": "0",
            "top": "0",
            "height": winHeight,
            "width": "100%",
            "z-index": "1000",
            "background-color": "rgba(0,0,0,0.8)",
            "filter": "alpha(opacity=80)"
        });
        $("#weixinTip p").css({
            "text-align": "center",
            "margin-top": "10%",
            "padding-left": "5%",
            "padding-right": "5%"
        });
        return false;
	}

    return true;
}